import cv2 as cv
import numpy as np

np.random.seed(1)

path = '../../../../../large_data/pic/weapon/yf-23.jpg'
img = cv.imread(path, cv.IMREAD_COLOR)
print(img.shape)
# cv.imshow('ori', img)

lap = cv.Laplacian(img, cv.CV_32F, None, 3)
cv.normalize(lap, lap, 1, 255, cv.NORM_MINMAX)
lap = np.uint8(lap)
# cv.imshow('lap', lap)

canny = cv.Canny(lap, 100, 200)
cv.imshow('canny', canny)

bg = np.zeros_like(img)
lines = cv.HoughLinesP(canny, 1, np.pi / 180, 30, minLineLength=30, maxLineGap=10)
for line in lines:
    for x1, y1, x2, y2 in line:
        cv.line(bg, (x1, y1), (x2, y2), (
            np.random.randint(0, 256),
            np.random.randint(0, 256),
            np.random.randint(0, 256),
        ), 1)
cv.imshow('HoughLinesP', bg)

cv.waitKey(0)
cv.destroyAllWindows()
